package com.headline.filter;// 1. 创建过滤器
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(urlPatterns = "/*") // 拦截所有请求
public class MyFilter implements Filter {
    
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        System.out.println("过滤器开始处理请求...");
        
        // 执行后续过滤器或请求处理
        chain.doFilter(request, response);
        
        System.out.println("过滤器处理请求结束...");
    }
    
    // 初始化和销毁方法可以根据需要实现
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("过滤器init...");
    }
    
    @Override
    public void destroy() {
        System.out.println("过滤器destroy...");
    }
}